<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="httpresponse-objects.html" />
<link rel="prev" href="module-httplib.html" />
<link rel="parent" href="module-httplib.html" />
<link rel="next" href="httpresponse-objects.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>18.7.1 HTTPConnection Objects </title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="18.7 httplib  "
  href="module-httplib.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="18.7 httplib  "
  href="module-httplib.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="18.7.2 httpresponse Objects"
  href="httpresponse-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-httplib.html">18.7 httplib  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-httplib.html">18.7 httplib  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="httpresponse-objects.html">18.7.2 HTTPResponse Objects</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION0020710000000000000000"></a><a name="httpconnection-objects"></a>
<br>
18.7.1 HTTPConnection Objects 
</h2>

<p>
<tt class="class">HTTPConnection</tt> instances have the following methods:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4026' xml:id='l2h-4026' class="method">request</tt></b>(</nobr></td>
  <td><var>method, url</var><big>[</big><var>, body</var><big>[</big><var>, headers</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
This will send a request to the server using the HTTP request method
<var>method</var> and the selector <var>url</var>.  If the <var>body</var> argument is
present, it should be a string of data to send after the headers are finished.
The header Content-Length is automatically set to the correct value.
The <var>headers</var> argument should be a mapping of extra HTTP headers to send
with the request.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4027' xml:id='l2h-4027' class="method">getresponse</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Should be called after a request is sent to get the response from the server.
Returns an <tt class="class">HTTPResponse</tt> instance.
<span class="note"><b class="label">Note:</b>
Note that you must have read the whole response before you can send a new
request to the server.</span>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4028' xml:id='l2h-4028' class="method">set_debuglevel</tt></b>(</nobr></td>
  <td><var>level</var>)</td></tr></table></dt>
<dd>
Set the debugging level (the amount of debugging output printed).
The default debug level is <code>0</code>, meaning no debugging output is
printed.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4029' xml:id='l2h-4029' class="method">connect</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Connect to the server specified when the object was created.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4030' xml:id='l2h-4030' class="method">close</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Close the connection to the server.
</dl>

<p>
As an alternative to using the <tt class="method">request()</tt> method described above,
you can also send your request step by step, by using the four functions
below.

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4031' xml:id='l2h-4031' class="method">putrequest</tt></b>(</nobr></td>
  <td><var>request, selector</var><big>[</big><var>,
skip_host</var><big>[</big><var>, skip_accept_encoding</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
This should be the first call after the connection to the server has
been made.  It sends a line to the server consisting of the
<var>request</var> string, the <var>selector</var> string, and the HTTP version
(<code>HTTP/1.1</code>).  To disable automatic sending of <code>Host:</code> or
<code>Accept-Encoding:</code> headers (for example to accept additional
content encodings), specify <var>skip_host</var> or <var>skip_accept_encoding</var>
with non-False values.

<span class="versionnote">Changed in version 2.4:
<var>skip_accept_encoding</var> argument added.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4032' xml:id='l2h-4032' class="method">putheader</tt></b>(</nobr></td>
  <td><var>header, argument</var><big>[</big><var>, ...</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Send an <a class="rfc" id='rfcref-102944' xml:id='rfcref-102944'
href="http://www.faqs.org/rfcs/rfc822.html">RFC 822</a>-style header to the server.  It sends a line to the
server consisting of the header, a colon and a space, and the first
argument.  If more arguments are given, continuation lines are sent,
each consisting of a tab and an argument.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4033' xml:id='l2h-4033' class="method">endheaders</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Send a blank line to the server, signalling the end of the headers.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-4034' xml:id='l2h-4034' class="method">send</tt></b>(</nobr></td>
  <td><var>data</var>)</td></tr></table></dt>
<dd>
Send data to the server.  This should be used directly only after the
<tt class="method">endheaders()</tt> method has been called and before
<tt class="method">getresponse()</tt> is called.
</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="18.7 httplib  "
  href="module-httplib.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="18.7 httplib  "
  href="module-httplib.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="18.7.2 httpresponse Objects"
  href="httpresponse-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-httplib.html">18.7 httplib  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-httplib.html">18.7 httplib  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="httpresponse-objects.html">18.7.2 HTTPResponse Objects</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
